<?php 
    $this->load->view("header2"); 
?>
<div id="map-canvas"></div>
<input type="hidden"  id="required_level" value="<?= !empty($post_data["required_level"])?$post_data["required_level"]:''; ?>" >
<input type="hidden"  id="name" value="<?= !empty($post_data["name"])?$post_data["name"]:''; ?>" >
<input type="hidden"  id="object_usage" value="<?= !empty($post_data["object_usage"])?$post_data["object_usage"]:''; ?>" >
<input type="hidden"  id="building_area1" value="<?= !empty($post_data["building_area1"])?$post_data["building_area1"]:''; ?>" >
<input type="hidden"  id="building_area2" value="<?= !empty($post_data["building_area2"])?$post_data["building_area2"]:''; ?>" >
<input type="hidden"  id="indoor_area1" value="<?= !empty($post_data["indoor_area1"])?$post_data["indoor_area1"]:''; ?>" >
<input type="hidden"  id="indoor_area2" value="<?= !empty($post_data["indoor_area2"])?$post_data["indoor_area2"]:''; ?>" >
<input type="hidden"  id="land_area1" value="<?= !empty($post_data["land_area1"])?$post_data["land_area1"]:''; ?>" >
<input type="hidden"  id="land_area2" value="<?= !empty($post_data["land_area2"])?$post_data["land_area2"]:''; ?>" >
<input type="hidden"  id="total_budget1" value="<?= !empty($post_data["total_budget1"])?$post_data["total_budget1"]:''; ?>" >
<input type="hidden"  id="total_budget2" value="<?= !empty($post_data["total_budget2"])?$post_data["total_budget2"]:''; ?>" >
<input type="hidden"  id="key_areas" value="<?= !empty($post_data["key_areas"])?$post_data["key_areas"]:''; ?>" >
<input type="hidden"  id="specify_building" value="<?= !empty($post_data["specify_building"])?$post_data["specify_building"]:''; ?>" >
<input type="hidden"  id="object_name" value="<?= !empty($post_data["object_name"])?$post_data["object_name"]:''; ?>" >

<input type="hidden"  id="sections1" value="<?= !empty($post_data["sections1"])?$post_data["sections1"]:''; ?>" >
<input type="hidden"  id="sections2" value="<?= !empty($post_data["sections2"])?$post_data["sections2"]:''; ?>" >


<div id="content">


        <link rel="stylesheet" href="<?= base_url() ?>css/crid_style.css" />
        <link rel="stylesheet" type="text/css" href="<?= base_url() ?>css/flexigrid.pack.css" />
        <script type="text/javascript" src="<?= base_url() ?>js/flexigrid.pack.js"></script>
        <script type="text/javascript" src="<?= base_url() ?>js/flexigrid2.js"></script>

		


        <table class="flexme4" style="display: none"></table>
 
    

        <script type="text/javascript">

            $(".flexme4").flexigrid({
                url : '/demand/demand_sf_josn',
                dataType : 'json',
                colModel : [ {
                    display : '編號',
                    name : 'demand_id',
                    width : '90',
                    sortable : true,
                    align : 'center'
                    },
                    {
                        display : '姓名',
                        name : 'name',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    }, 
                    {
                        display : '住家住址',
                        name : 'home_address',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    },
                    {
                        display : '面積',
                        name : 'building_area1',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    },
                    {
                        display : '室內面積',
                        name : 'indoor_area1',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    },
                    {
                        display : '土地面積',
                        name : 'land_area1',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    },
                    {
                        display : '路段',
                        name : 'sections1',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    },
                    {
                        display : '重地區域',
                        name : 'key_areas1',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    },
                    {
                        display : '商圈',
                        name : 'circle1',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    },
                    {
                        display : '總價',
                        name : 'total_budget1',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    },
                    {
                        display : '經紀人',
                        name : 'broker',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    },
                    {
                        display : '物件用途',
                        name : 'object_usage',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    },
                    {
                        display : '類型',
                        name : 'type_rent',
                        width : 100,
                        sortable : true,
                        align : 'left'
                    }
                        ],
                buttons : [ 
                    {
                        name : '編輯',
                        bclass : 'edit',
                        onpress : Example4
                    }
                    ,
                    {
                        name : 'Excel',
                        bclass : 'coffee',
                        onpress : Example4
                    }
                    ,
                    {
                        name : '配對',
                        bclass : 'pattern',
                        onpress : Example4
                    }
                    ,
                    {
                        name : '删除',
                        bclass : 'delete',
                        onpress : Example4
                    }                    
                    ,
                    {
                        separator : true
                    } 
                ],
                searchitems : [ 
                    
                    {
                        display : '姓名',
                        name : 'name',
                        isdefault : true
                    }
                    , 
                    {
                        display : 'home_address',
                        name : 'home_address',
                        isdefault : true
                    }
                     ],
                sortname : "demand_id",
                sortorder : "asc",
                usepager : true,
                title : '需求列表',
                checkbox : true,// 是否要多選框
                useRp : true,
                rp : 10,
                width: 'auto',
                height: 'auto',
                
                procmsg:'資料讀取中，請稍後…', 
                nomsg:'找不到符合絛件的資料',                  
                
                //margin: 10px 1palex 1px -53px
            });
            
            function Example4(com, grid) {

            if (com == '删除') {


                var empty_str ='';
                var _fg =true;
                  $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');                    

                    if(_fg){

                      _fg = false;
                      empty_str+= parseInt(str[1]);

                    }else{

                      empty_str+= ","+parseInt(str[1]);

                    }
                });  

                
                $.post('/demand/save_demand_id', {

                        id : empty_str ,
                        is_del : '0'

                }, function(data) {
                        
                        $.post('/demand/del_demand_id', {
                                          
                        }, function(data) {  
                             $(".flexme4").flexReload();    
                        });       
                });  

            }else if (com == '編輯') {


                
                  $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');

                    var url = '/demand/data_edit?id='+parseInt(str[1]);
                 
                    document.location.href = url;
                    
                });  

                 

            }
            else if (com == '配對') {
                var tr_ed = $('.trSelected', grid).length;

                if(tr_ed == 1 ){

                    $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');

                    var url = '/pair/demand?id='+parseInt(str[1]);
                 
                    document.location.href = url;
                    
                    }); 
                 
                 

                }else{
                    alert('一次只能選取一個');
                }              
            }
            else if (com == 'Add') {

            }
            else if (com == 'Excel') { 
                
                var empty_str ='';
                var _fg =true;
                $(".trSelected").each(function() {

                    var str = $(this).children().next().html();
                    var str2 = str.split('</div>');
                    var str = str2[0].split('>');

                    if(_fg){
                      _fg = false;
                      empty_str+= parseInt(str[1]);
                    }else{
                      empty_str+= ","+parseInt(str[1]);

                    }
                });

                

                $.post('/demand/save_demand_id', {
                        id : empty_str ,
                        is_del : '0'
                }, function(data) {

                        var url = '/demand/excel';                
                        document.location.href = url;          
                });                                  
            }



        }

           




        function query() {
            
           
            var name = $("#name").val();
            
            var required_level = $("#required_level").val();
            var object_usage   = $("#object_usage").val();
            
            var building_area1   = $("#building_area1").val();
            var building_area2   = $("#building_area2").val();
            
            var indoor_area1   = $("#indoor_area1").val();
            var indoor_area2   = $("#indoor_area2").val();
            
            var land_area1   = $("#land_area1").val();
            var land_area2   = $("#land_area2").val();

            var total_budget1   = $("#total_budget1").val();
            var total_budget2   = $("#total_budget2").val();

            var key_areas   = $("#key_areas").val();
            var specify_building   = $("#specify_building").val();

            var object_name   = $("#object_name").val();
            
            var sections1   = $("#sections1").val();
            var sections2   = $("#sections2").val();
            

            
            $(".flexme4").flexOptions(
                    {newp: 1, params:
                                [
                                    {name: 'name',
                                        value: name}                                                                        
                                    ,                                    
                                    {name: 'sections1',
                                        value: sections1}
                                    ,                                    
                                    {name: 'sections2',
                                        value: sections2}
                                    ,                                    
                                    {name: 'object_name',
                                        value: object_name}        
                                    ,                                    
                                    {name: 'specify_building',
                                        value: specify_building}    
                                    ,                                    
                                    {name: 'key_areas',
                                        value: key_areas}    
                                    ,                                    
                                    {name: 'total_budget1',
                                        value: total_budget1}    
                                    ,                                    
                                    {name: 'total_budget2',
                                        value: total_budget2}
                                    ,                                    
                                    {name: 'land_area1',
                                        value: land_area1}        
                                    ,                                    
                                    {name: 'land_area2',
                                        value: land_area2}
                                    ,                                    
                                    {name: 'indoor_area1',
                                        value: indoor_area1}                                            
                                    ,                                    
                                    {name: 'indoor_area2',
                                        value: indoor_area2}
                                    ,                                    
                                    {name: 'building_area1',
                                        value: building_area1}                                                
                                    ,                                    
                                    {name: 'building_area2',
                                        value: building_area2}    
                                    ,                                    
                                    {name: 'object_usage',
                                        value: object_usage}                                                                                                                 
                                    ,                                    
                                    {name: 'required_level',
                                        value: required_level}                                                                                                   
                                ]
                    }).flexReload();
        }

         $("document").ready(function() {

            setTimeout('query()', 200);

            });
        </script>
</div>
<?=isset($footer) ? $footer : ''?>